package com.xiaowu.netmusic.service.impl;

import com.xiaowu.netmusic.service.AliOssService;
import com.xiaowu.netmusic.utils.AliOssUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

// AliOssServiceImpl.java
@Service
@RequiredArgsConstructor
public class AliOssServiceImpl implements AliOssService {

    private final AliOssUtil aliOssUtil;

    @Override
    public String uploadAudio(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String extension = originalFilename.substring(originalFilename.lastIndexOf("."));
        String objectName = "audio/" + UUID.randomUUID() + extension;

        // 上传到 OSS 并获取 OSS 返回的路径
        String ossUrl = aliOssUtil.upload(file.getBytes(), objectName);

        // 这里的 ossUrl 应该是阿里云的完整 URL，不需要再拼接你的域名
        return ossUrl;
    }

}
